<?xml version="1.0" encoding="UTF-8"?>
<%! import rage.Geometry %>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
	<g:if test="${flash.message}">
           	<Placemark>
			<name>ERROR</name>
			<description>${flash.message}</description>
		</Placemark>
	</g:if>
	<g:else>
		<Style id="<g:rgbToBGR>${feedColor}</g:rgbToBGR>_normal">
			<LabelStyle>
				<color>00ffffff</color>
			</LabelStyle>
			<IconStyle>
				<color>ff<g:rgbToBGR>${feedColor}</g:rgbToBGR></color>
				<scale>1</scale>
				<Icon>
					<href>http://maps.google.com/mapfiles/kml/paddle/wht-blank.png</href>
 				</Icon>
			</IconStyle>
			<LineStyle>
				<color>7d<g:rgbToBGR>${feedColor}</g:rgbToBGR></color>
				<width>2.0</width>
			</LineStyle>
			<PolyStyle>
				<color>7d<g:rgbToBGR>${feedColor}</g:rgbToBGR></color>
				<colorMode>normal</colorMode>
				<fill>false</fill>
				<outline>true</outline>
			</PolyStyle>
			<BalloonStyle>
				<text>$[description]</text>
			</BalloonStyle>
		</Style>
		<Style id="<g:rgbToBGR>${feedColor}</g:rgbToBGR>_highlighted">
			<LabelStyle>
				<color>ffffffff</color>
			</LabelStyle>
			<IconStyle>
				<color>ff<g:rgbToBGR>${feedColor}</g:rgbToBGR></color>
				<scale>1.4</scale>
				<Icon>
					<href>http://maps.google.com/mapfiles/kml/paddle/wht-blank.png</href>
 				</Icon>
			</IconStyle>
			<LineStyle>
				<color>7d<g:rgbToBGR>${feedColor}</g:rgbToBGR></color>
				<width>2.0</width>
			</LineStyle>
			<PolyStyle>
				<color>7d<g:rgbToBGR>${feedColor}</g:rgbToBGR></color>
				<colorMode>normal</colorMode>
				<fill>false</fill>
				<outline>true</outline>
			</PolyStyle>
			<BalloonStyle>
				<text>$[description]</text>
			</BalloonStyle>
		</Style>
		<StyleMap id="<g:rgbToBGR>${feedColor}</g:rgbToBGR>">
			<Pair>
				<key>normal</key>
				<styleUrl>#<g:rgbToBGR>${feedColor}</g:rgbToBGR>_normal</styleUrl>
			</Pair>
			<Pair>
				<key>highlight</key>
				<styleUrl>#<g:rgbToBGR>${feedColor}</g:rgbToBGR>_highlighted</styleUrl>
			</Pair>
		</StyleMap>
		<g:each in="${feedInstance.placemarks}" status="i" var="placemarkInstance">
			<g:if test="${placemarkInstance.kmlEnclosures}">
				<Folder>
					<name><![CDATA[${placemarkInstance.name}]]></name>
			</g:if>
			<Placemark>
				<name><![CDATA[${placemarkInstance.name}]]></name>
				<description>
					<![CDATA[${placemarkInstance.description}]]>
				</description>
				<styleUrl>#<g:rgbToBGR>${feedColor}</g:rgbToBGR></styleUrl>
				<g:if test="${placemarkInstance.timestamp}">
					<TimeStamp>
						<when>${placemarkInstance.timestamp}</when>
					</TimeStamp>
				</g:if>
				<g:if test="${placemarkInstance.geometryList == null}">
					<Snippet>
						No geolocation data available!
					</Snippet>
				</g:if>
				<g:elseif test="${placemarkInstance.geometryList.size() >= 1}">
					<MultiGeometry>
						<g:each in="${placemarkInstance.geometryList}" status="j" var="geometryInstance">
							<g:if test="${geometryInstance.type == Geometry.Type.POINT}">
								<Point>
									<coordinates>${geometryInstance.points.get(0).getX()},${geometryInstance.points.get(0).getY()},0</coordinates>
								</Point>
							</g:if>
							<g:elseif test="${geometryInstance.type == Geometry.Type.POLYGON}">
								<Point>
									<coordinates>${geometryInstance.points.get(0).getX()},${geometryInstance.points.get(0).getY()},0</coordinates>
								</Point>
								<Polygon>
									<outerBoundaryIs>
										<LinearRing>
											<coordinates>
												<g:each in="${geometryInstance.points}" status="k" var="pointInstance">
													${pointInstance.getX()},${pointInstance.getY()},0</g:each>
											</coordinates>
										</LinearRing>
									</outerBoundaryIs>
								</Polygon>
							</g:elseif>
						</g:each>
					</MultiGeometry>
				</g:elseif>
				<g:else>
				</g:else>
			</Placemark>
			<g:if test="${placemarkInstance.kmlEnclosures}">
				<g:each in="${placemarkInstance.kmlEnclosures}" var="enclosure">
					<NetworkLink>
						<name><![CDATA[${enclosure.key}]]></name>
						<visibility>0</visibility>
						<open>0</open>
						<flyToView>0</flyToView>
						<Link>
							<href>${enclosure.value}</href>
						</Link>
					</NetworkLink>
				</g:each>
				</Folder>
			</g:if>
		</g:each>
	</g:else>
	</Document>
</kml>